<?php
class Datanews extends CI_Controller{
	/**
	 *
	 * 构造函数
	 */
	function Datanews()
	{
		parent::__construct();
		// load helpers
		$this->load->helper('url');
		//$this->load->helper('form');
		//$this->load->helper(array('form','url'));
		//$this->form_validation->//...
		//$this->load->library('form_validation');
	}

	/**
	 * 首页
	 */
	function index() {
		$this->load->model('MDatanews', 'mdn');
		$data['datanews'] =$this->mdn->get_last_ten_datanews();
		$this->load->view('datanews/index',$data);
	}

	/**
	 * 添加页面
	 *
	 */
	function add()
	{
		//$this->load->helper('date');
		// display information for the view
		$this->load->library('ckeditor');
		$this->ckeditor->basePath = base_url().'ckeditor/';
		$this->ckeditor->returnOutput = true;
		$data['ckeditor'] = $this->ckeditor->editor('content');
		$this->load->view('datanews/add', $data);
	}

	/**
	* 保存页面
	* @param unknown_type $data
	*/
	function insert(){
		//设置数据格式
		date_default_timezone_set('Asia/Shanghai');
		//构造插入数据的数组
		$data = array(
			            'title'=>$_POST['title'],
			            'content'=>$_POST['content'],
			            'creatdate'=>date("Y-m-d H:i:s")
		);
		$this->load->model('MDatanews', 'mdn');
		$this->mdn->saveDataNews($data);
		//跳转
		redirect('datanews/index','refresh');
	}

}
?>